/*-------------------------------------------------------------------------


***************** Modification History ***********************************
   @doc
   @module Pinpad.h - Header file for pinpad functionality |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/Include/pinpad.h $ 
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/

#ifdef  PINPAD_DEFINED

#ifndef VSPINPAD
#define VSPINPAD

#include <transact.h>

#define BPI_MAC             0       /* BPI alogorithm  */
#define ANSI_MAC            1       /* ANSI algorithm */
                            
#define ASCII               0
#define BINARY              1

#define PP_MAX_RETRIES      3       /* Maximum number of retries */
#define PINPAD_BUF_SIZE     250     /* Max size for PP RX and TX buffers */

/* PINpad response codes */
#define PP_SUCCESS          0       
#define PP_ERROR            1
#define PP_TIMEOUT          2
#define PP_CANCEL           3
#define PP_CORRECT          4
#define PP_BADBALANCE       5
#define PP_BADACCTLEN       6
#define PP_MACFAILED        7
#define PP_NOMACBLOCK       9
#define PP_BADDECRYPTION    11
#define PP_NEWKEYSFAILED    16
#define PP_CANNOTREVERTKEYS 98
#define PP_SC_FAILED        99

#define PPADTIMEOUT         6
#define PPAD501TIMEOUT      12

#define PINPAD_PIN_RESP_LEN 27      /* Normal length of resp pkt for PIN */
#define PINPAD_BUFFER_SIZE  150
#define LAST                0       /* Used in MACing */
#define TIMEOUT_DELAY       10      /* Timeout needed for PinPad */

#define CLR                 0x1A    /* Clear the pinpad screen or not */
#define MAX_ACT_RETRYS      3       /* Account Entry Max retries */

/* Format flags 0-4 with Fmt_Auto setting */
#define Fmt_A7E1_auto       10
#define Fmt_A7N1_auto       11
#define Fmt_A7O1_auto       12
#define Fmt_A8E1_auto       13
#define Fmt_A8N1_auto       14

#define PINPAD_MESSAGE_FILE "pin"

/* Structure passed as input for PIN Encryption */
typedef struct tagPinInfoStruct
{
    char pchPrimaryAcctInfo[19+1];
    char pchDispStr1[16+1];
    char pchDispStr2[16+1];
    char pchEncryptionKey[16+1];
    char pchMaxPIN[2+1];
    char pchMinPIN[2+1];
    int  inKeySlotPos;
    char pchDispOver[16+1];
    char pchEncryptedPIN[16+1];
} PININFOSTRUCT;


typedef struct tagPinPadObject
{
    int inHandle;
    int inType;
    int inTimeout;      /* PPADTIMEOUT, PPAD501TIMEOUT */

    /* Function pointers for object */
    int (*inInitPinPad)(void);
    int (*inSetPinPadIdlePrompt)(void);
    int (*inDisplayPinPadString)(char chClrDisplay, char *chDispString);
    int (*inGetPin)(TRANSACTION_OBJECT *pobTran);
    int (*inGetTipAmount)(TRANSACTION_OBJECT *pobTran);
    int (*inPPadConnectTest)(void);
    void(*vdSendAbortToPINPad)(void);
    
} PINPAD_OBJECT;

extern PINPAD_OBJECT obPinPad;
extern VS_BOOL   gfPPadPresent;   /* Global flag to determine if PinPad is present */

#ifdef MAC

typedef struct
{
    int  inPINPadType;
    int  inKeySlot;
    int  inMacDataType;
    char pchMacKey[16+1];
    char pchMacSecKey[16+1];
    int  inMacType;
    char pchTerminalMac[8+1];
    char pchHostMac[8+1];
} MACINFOSTRUCT;

#endif /* MAC */

int  inAddPinPadFunctions(void);
int  inColdInitPinpad(TRANSACTION_OBJECT *pobTran);
int  inInitializePinPad(void);
int  inInitPinPad(void);
int  inSendPinPadData(char *pchMsg, int inTimeOut, VS_BOOL fWaitForAck);
int  inRecvPinPadData(char *pchRecBuf, int inTimeOut, int inMaxRecSize, VS_BOOL fSendAck);
int  inImamRecvPinPadData(char *pchRecBuf, int inTimeOut, int inMaxRecSize, VS_BOOL fSendAck);
int  inPPDispBalance(char *pszBalance);
void vdPPAdvTransFailed(void);
void vdPPAdvObtainCard(void);
int  inSetPPIdlePrompt(void);
int  inResetPINPad(void);
int  inDispPPStr(char chClrDisplay, char *chDispStr);
int  inPPadConnectTest(void);
int  inGetPin(TRANSACTION_OBJECT *pobTran);
int  inGetTipAmt(TRANSACTION_OBJECT *pobTran);
void vdSendAbortToPINPad(void);
int  inGetPinTip(TRANSACTION_OBJECT *pobTran);
int  inSelectMasterKey(void);
int  inImamTransferMasterKey(char MKAddress, char *szMasterKey);
int  inSetupPinPad(int inPinPadType);
int  inDebitBalanceDisplay(TRANSACTION_OBJECT *pobTran);
int  inDisplayBalanceOnPINPad(TRANSACTION_OBJECT *pobTran);
int  inDebitReset(TRANSACTION_OBJECT *pobTran);
int  inExecPinPadIdlePrompt(void);
int  inSetupPinPadInfo(int inPinPadType);
int  inSetupIPPInfo(int inPinPadType);
int  inSetIPPIdlePrompt(void);
int  inGetPinEntry(long lnMessage, char *pszBuffer, int inMinChars, int inMaxChars);
int  inDispIPPStr(char chClrDisplay, char *pszDispStr);
int  inGetIPPPin(TRANSACTION_OBJECT *pobTran);
int  inGetIPPTipAmt(TRANSACTION_OBJECT *pobTran);
void vdDispPinPadPkt73Error(char chError);
int  PINPAD_CODE_CHECK(char * a,char *b,short *  c,char * d,unsigned char * e);
void vdUpperCasePinMsg(char *pchString);

extern int inGetPinAccMac(TRANSACTION_OBJECT *pobTran);
int inHHGetPinAccMac(TRANSACTION_OBJECT *pobTran);

#endif  /* VSPINPAD */

#endif  /* PINPAD_DEFINED */



